package ooday03;
/** 引用类型数组的演示 */
public class RefArrayDemo {
    public static void main(String[] args) {
        /*
        //声明Dog型数组dogs，包含3个元素，每个元素都是Dog型，默认值为null
        Dog[] dogs = new Dog[3];
        //声明Chick型数组chick，包含3个元素，每个元素都是chick型，默认值为null
        Chick[] chick = new Chick[3];
        //声明Fish型数组Fish，包含2个元素，每个元素都是Fish型，默认值为null
        Fish[] fish = new Fish[2];
         */
        /*
        String[] a = new String[3];
        a[0] = new String("sdasd");
        a[2] = "dasd";
        Dog[] dogs = new Dog[3];
        dogs[0] = new Dog("小黄",2,"黄");
        dogs[1] = new Dog("小黑",1,"黑");
        dogs[2] = new Dog("小白",3,"白");
        Fish[] fish = new Fish[3];
        fish[0] = new Fish("小鱼",1,"白");
        fish[1] = new Fish("鱼儿",2,"蓝");
        fish[2] = new Fish("大鱼",3,"金");
        Chick[] chick = new Chick[3];
        chick[0] = new Chick("鸡鸡",2,"花");
        chick[1] = new Chick("大鸡",3,"黑");
        chick[2] = new Chick("小鸡",1,"黄");
         */

        Dog[] dogs = new Dog[3];
        dogs[0] = new Dog("小黑",3,"黑");
        dogs[1] = new Dog("大白",3,"白");
        dogs[2] = new Dog("胖虎",3,"棕");
        dogs[1].age = 4;
        dogs[2].swim();
        for (int i=0;i< dogs.length;i++){
            System.out.println(dogs[i].name);
            dogs[i].eat();
        }
        Chick[] chick = new Chick[2];
        chick[0] = new Chick("小鸡",1,"黄");
        chick[1] = new Chick("花鸡",3,"花");
        for (int i=0;i< chick.length;i++){
            System.out.println(chick[i].age);
            chick[i].layEggs();
        }
        Fish[] fish = new Fish[3];
        fish[0] = new Fish("大鱼",3,"黑");
        fish[1] = new Fish("鱼",2,"白");
        fish[2] = new Fish("小鱼",1,"黄");
        for (int i=0;i< fish.length;i++){
            System.out.println(fish[i].color);
            fish[i].drink();
        }
    }
}
